package com.example.mapp;

import com.example.entity.MessageNotice;
import com.example.ext.entity.ExtMessageNotice;
import com.example.mapp.buildSql.MessageNoticeMappSql;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * Created by youkun on 2017/10/3.
 */
@Mapper
public interface MessageNoticeMapp {

    @Select("select m.* ,s.user_name as receiveUserName from message_notice as m LEFT JOIN sys_user as s on m.receive_user_id = s.id where m.id=#{id}")
    MessageNotice findById(String id)throws Exception;

    @SelectProvider(type = MessageNoticeMappSql.class,method = "findUserInfos")
    List<Map<String, Object>> findUserInfos(Map<String,Object> param)throws Exception;

    @Delete("delete from message_notice where id=#{id}")
    int deleteById(String id)throws Exception;

    @Insert("insert into message_notice (title,content,file_urls,send_user_id,receive_user_id,is_read, notice_time,elevatori_type,elevatori_mon_id) " +
            "value (#{title},#{content},#{fileUrls},#{sendUserId},#{receiveUserId},#{isRead},#{noticeTime},#{elevatoriType},#{elevatoriMonId})")
    @SelectKey(statement="select last_insert_id()",keyProperty = "id",keyColumn = "id",before = false,resultType = Long.class)
    int add(MessageNotice messageNotice) throws Exception;

    @Update(" update message_notice set title=#{title},content=#{content},file_urls=#{fileUrls},send_user_id=#{sendUserId}," +
            "receive_user_id=#{receiveUserId},is_read=#{isRead} where id=#{id}")
    int update(MessageNotice messageNotice) throws Exception;

    @Update(" update message_notice set is_read=#{isRead} where id=#{id}")
    int updateReadState(Map<String,Object> messageNotice) throws Exception;

    @SelectProvider(type = MessageNoticeMappSql.class,method = "queryList")
    List<ExtMessageNotice> queryList(ExtMessageNotice extMessageNotice) throws Exception;

    @SelectProvider(type = MessageNoticeMappSql.class,method = "querySendList")
    List<ExtMessageNotice> querySendList(ExtMessageNotice extMessageNotice) throws Exception;

    @SelectProvider(type = MessageNoticeMappSql.class,method = "countList")
    int countList(ExtMessageNotice extMessageNotice) throws Exception;
}
